package szc.common.code.counter;

import szc.common.code.rule.CodeLineParserAbstract;

import java.util.List;

/**
 * @desc 无效代码行统计
 * @author songzc
 * @date 2022/6/18
 */
public class NoValidCodeLineCounter {
    private List<CodeLineParserAbstract> noValidCodeLineParserGroup;
    private int noValidCodeLineCounter = 0;
    private boolean isNoValidCodeLine = false;

    /**
     * 自定义解析器组
     * @param noValidCodeLineParserGroup
     */
    public NoValidCodeLineCounter(List<CodeLineParserAbstract> noValidCodeLineParserGroup){
        this.noValidCodeLineParserGroup = noValidCodeLineParserGroup;
    }

    public void countNoValidCodeLine(String codeLine) {
        for (CodeLineParserAbstract parser : this.noValidCodeLineParserGroup) {
            parser.setCodeLine(codeLine);
            if (parser.parseCodeLine()) {
                this.isNoValidCodeLine = true;
                this.noValidCodeLineCounter++;
                break;
            } else {
                this.isNoValidCodeLine = false;
            }
        }
    }

    public int getLineCount() {
        return this.noValidCodeLineCounter;
    }

    public boolean isNoValidCodeLine() {
        return this.isNoValidCodeLine;
    }
}
